<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script src="../js/flexible.js"></script>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/job/style.css">
    <style>
        #pullUp{
            display: none !important;
        }
    </style>
    <title>发布列表</title>
</head>

<body>
    <div id="J_wrapper" class="container">
        <div id="scroller">
            <div id="pullDown">
                <span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新</span>
            </div>
            <div class="j_container_wrap">
            </div>
            <!--  end -->
            <div id="pullUp">
                <span class="pullUpIcon"></span><span class="pullUpLabel"></span>
            </div>
        </div>
    </div>
    <div class="tabs_wrap change_tabs_wrap hide" id="J-tab-wrap">
        <ul class="clearfix">
            <li class="active"><a class="btn1" href="javascript:;">我的发布</a></li>
            <li><a class="btn2 cur" href="publishTask.html">发布新招聘</a></li>
            <li><a class="btn3" href="msg-list.html">任务动态 <i class="new_ico hide"></i></a></li>
        </ul>
    </div>
</body>
<script src='//cdn.bootcss.com/socket.io/1.3.7/socket.io.js'></script>
<script src="../js/jquery.min.js"></script>
<script src="../js/fastclick.js"></script>
<script src="../js/scroll/iscroll.js"></script>
<script src="../js/scroll/scroll-init.js"></script>
<script src="../js/ajax/jsencrypt.js"></script>
<script src="../js/ajax/ajax.js"></script>
<script src="../js/main.js"></script>
<script type="text/javascript">
FastClick.attach(document.body);

function getRowHtml(data) {
    var arr1 = [],
        state = data.t_status_id;
    var start_time = data.t_start_time;
    var end_time = data.t_end_time;
    var created_year = (data.t_created_at).substr(0, 10);
    arr1.push('<div class="list_wrap"><div class="list_box" data-taskId="' + data.t_id + '">');
    if (state == "3") {
        arr1.push('<h3 class="caption clearfix paying">待支付<i class="jiantou"></i></h3>');
    } else if (state == "2") {
        arr1.push('<h3 class="caption change_color clearfix working">工作中<i class="jiantou"></i></h3>');
    } else if (state == "1") {
        arr1.push('<h3 class="caption change_color2 clearfix zping">招聘中<i class="jiantou"></i></h3>');
    } else if (state == "4") {
        arr1.push('<h3 class="caption clearfix ending">已结束<i class="jiantou"></i></h3>');
    } else if (state == "10") {
        arr1.push('<h3 class="caption clearfix zending">招聘结束<i class="jiantou"></i></h3>');
    }
    arr1.push('<h4 class="tit_box clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr1.push(' <div class="join_box change_join_box">');
    arr1.push('<span class="moneyT change_position"><i class="time">￥' + data.t_price + '</i>/时</span>');
    arr1.push('</div><div class="txt_box"><p><i class="time_ico"></i><span class="long-desc">' + start_time + '-' + end_time + '</span></p>');
    arr1.push(' <p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr1.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
      arr1.push(' <p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元');
    arr1.push('<span>用餐时间:' + data.t_dinner_time + '分钟</span>');
    arr1.push('<span>其他:' + data.t_other_subsidy + '元</span>');
    arr1.push('</span></p><p><i class="map_ico"></i>' + data.t_workplace + '</p>');
    arr1.push('</div></div></div>');
    arr1.push('<div class="dates">' + created_year + '</div>');
    return arr1.join(' ');
}

var count_pages = 1;
var manageId = 2;
var userType = 2;
var stateFlag = false;
if (GetQueryString("userId")) {
    manageId = GetQueryString("userId"); //获取当前会话的id
}
if (GetQueryString("type")) {
    userType = GetQueryString("userType"); //获取当前的用户类型
}
localStorage.setItem("o_flag", ""); //清除掉详情页缓存的数据

if (userType == 2) {
    $("#J-tab-wrap").show();
    start.postAjaxReq({
        param: {
            "id": manageId
        },
        type: "GET",
        url: "/message/isRead",
        success: function(data) {
            if(!!data.errmsg){
                $(".new_ico").removeClass("hide");
            }
        },
        errorCb: function(data) {}
    });
}

function pullUpAction() {
    if (stateFlag) {
        return false;
    }
    start.postAjaxReq({
        param: {
            "id": manageId,
            "type": userType,
            "page_size": 5,
            "page": count_pages
        },
        type: "GET",
        url: "/task/getTaskList",
        success: function(data) {
            var meta = data.result.meta;
            var html = '',
                now, obj = data.result.data;
            if (obj.length > 0) {
                for (var i = 0; i < obj.length; i++) {
                    now = obj[i];
                    html += getRowHtml(now);
                }
                $(".j_container_wrap:visible").append(html);
                count_pages++;
                myScroll.refresh();
            } else {
                if (count_pages == 1 && obj.length == 0) {
                    html = shoNoData();
                    stateFlag = true;
                }
                $(".j_container_wrap:visible").append(html);
                return false;
            }
            if (meta.current_page == meta.total_pages) {
                showFadeData();
                stateFlag = true;
            }

        },
        errorCb: function(data) {
            
        }
    });
}
$(function() {
    localStorage.setItem('data_taskId', ""); //清除任务id
    localStorage.setItem('isEdit', "");



    pullUpAction();
    $(document).delegate(".list_box", 'click', function() {
        localStorage.setItem('data_taskId', $(this).data('taskid'));
        location.href = "manager-deta.html";
    });

    // 连接服务端
    var socket = io('192.168.31.225:2120');
    // 连接后登录
    socket.on('connect', function() {
        socket.emit('login', manageId);
    });
    // 后端推送来消息时
    socket.on('new_msg', function(msg) {
        $(".new_ico").removeClass("hide");
    });

});
</script>

</html>
